package com.ara.x.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.viewpager2.widget.ViewPager2;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.ara.common.kernel.base.BaseActivity;
import com.ara.common.kernel.dialog.XPromptDialog;
import com.ara.x.R;
import com.ara.x.adapter.MainFragmentStateAdapter;
import com.ara.x.constant.MainRouterApiConstant;
import com.ara.x.databinding.ActivityMainBinding;
import com.gyf.immersionbar.ImmersionBar;


@Route(path = MainRouterApiConstant.API_MAIN)
public class MainActivity extends BaseActivity<ActivityMainBinding> {
    private MainFragmentStateAdapter adapter;

    @Override
    public void initView(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        ImmersionBar.with(this).transparentStatusBar().fitsSystemWindows(false).statusBarDarkFont(true).init();
        adapter = new MainFragmentStateAdapter(this);
        binding.viewPager.setAdapter(adapter);
        binding.viewPager.setUserInputEnabled(false); //true:滑动，false：禁止滑动

        new XPromptDialog.Builder(getContext()).show();
    }

    @Override
    public void initListener() {
        binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    binding.navView.setSelectedItemId(R.id.navigation_home);
                } else if (position == 1) {
                    binding.navView.setSelectedItemId(R.id.navigation_my);
                }
                super.onPageSelected(position);
            }
        });
        binding.navView.setOnNavigationItemSelectedListener(item -> {
            if (item.getItemId() == R.id.navigation_home) {
                binding.viewPager.setCurrentItem(0);
            } else if (item.getItemId() == R.id.navigation_my) {
                binding.viewPager.setCurrentItem(1);
            }
            return true;
        });
    }
}